package com.tech.arno.spicy.mvp.presenterImpl;

import com.tech.arno.spicy.mvp.listener.OnLoginFinishedListener;
import com.tech.arno.spicy.mvp.model.LoginModel;
import com.tech.arno.spicy.mvp.modelImpl.LoginModelImpl;
import com.tech.arno.spicy.mvp.presenter.LoginPresenter;
import com.tech.arno.spicy.mvp.view.LoginView;

/*
*   @package:     com.tech.arno.spicy.mvp.presenterImpl
*   @fileName:    LoginPresenterImpl
*   @author:    ArnoFrost
*   @date:  2017/12/22 0022 8:35
*   @desc:     登录Presenter实现
*/

public class LoginPresenterImpl implements LoginPresenter, OnLoginFinishedListener {
    private LoginView loginView;
    private LoginModel loginModel;

    public LoginPresenterImpl(LoginView loginView) {
        this.loginView = loginView;
        this.loginModel = new LoginModelImpl();
    }

    @Override
    public void login(String username, String password) {
        loginModel.login(username, password, this);
    }

    @Override
    public void onDestroy() {
        loginView = null;
    }

    @Override
    public void onUsernameError() {

    }

    @Override
    public void onPasswordError() {

    }

    @Override
    public void onSuccess() {
        if (loginView != null) {
            loginView.loginSuccess();
        }
    }

    @Override
    public void onError() {
        if (loginView != null) {
            loginView.loginError();
        }
    }
}
